package com.lee.service;

import com.lee.domain.EmployeeSocial;
import com.lee.repository.EmployeeSocialRepository;
import com.lee.security.provider.social.SocialDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationServiceException;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * @author Lee HN
 * @date 2019/7/8 13:47
 */
@Service
public class SocialDetailsServiceImpl implements SocialDetailsService {

    @Autowired
    private EmployeeSocialRepository employeeSocialRepository;

    @Override
    public String getUsername(String providerId, String openId) {
        Optional<EmployeeSocial> employeeSocialOP = employeeSocialRepository.findById(EmployeeSocial.SocialKey.of(providerId, openId));
        return employeeSocialOP.orElseThrow(() -> new AuthenticationServiceException("用户第三方绑定信息不存在")).getUsername();
    }
}
